<%@ page language="java" import="java.util.Map,org.json.*,java.sql.*,com.microsoft.sqlserver.jdbc.*,java.io.*,web.rec.*" 
contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"  %>

<% 
	ResourceTool.init();
/*	String form = request.getParameter("form");
	if(form!=null)
		ResourceTool.setForm(form);
	else{
		response.sendRedirect("mainPage.jsp");
		return;
	}
*/
	String CURRENT_YEAR = "2012";
	String CURRENT_SEASON = "Fall";

	String action = request.getParameter("action");
	if(action != null ){
		if(action.equals("insert")){
			ResourceTool.insertDBForEachTable(request,"Quarter");
			ResourceTool.insertDBForEachTable(request,"StudentTakingSection");
			ResourceTool.insertDBForEachTable(request,"StudentQuarterEnrolled");
		}
		else if(action.equals("update") || action.equals("delete")){
			ResourceTool.modifyDBForEachTable(request,action,"Quarter");
			ResourceTool.modifyDBForEachTable(request,action,"StudentTakingSection");  
			ResourceTool.modifyDBForEachTable(request,action,"StudentQuarterEnrolled");
		}
	}
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="script/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="script/form_script.js"></script>
<script type="text/javascript" src="script/json2s.js"></script>
<link rel="stylesheet" type="text/css" href="style/mainstyle.css" />


</head>
<body>
<div>
<div id="menu">
	<%
		Map<String,String[]> map = ResourceTool.menuMap;
		for(String key: map.keySet()){
	%>
	<div>
		<h3><%= key %></h3>
		<%= ResourceTool.getMenu(key) %>
	</div><br />
	<%
		}
	%>
</div>

<div id="content" style="width:700px">
<h1>Classes Taken</h1><div id='queryError'><%= ResourceTool.getErrorString() %></div>
<form method="get" action="ClassesTaken.jsp" >
	<!-- <table id="input_table"> -->
	<div id="input_div" style="width:700px">
		<div>
			<p>student id</p><br />
			<input type="text" class="field" name="student_id" value="" />
		</div>
		<div>
			<p>year</p><br />
			<input type="text" name="year" id="form_action" value="" />
		</div>
		<div>
			<p>season</p><br />
			<input type="text" name="season" id="form_action" value="" />
		</div>
		<div>
			<p>course num</p><br />
			<select size="10" name="course_num" class="field" style="width:80px">
				<%
					Connection conn = ResourceTool.getConnection();
					Statement stmt = conn.createStatement();
					ResultSet rs = stmt.executeQuery("SELECT course_num FROM Course");
					while(rs.next()){
				%>
						<option><%=rs.getString(1) %></option>
				<%		
					}
				%>
			</select>
			<br />
			<!--script function query(tables , pkey,targetName) -->
			<button value='search' onclick="queryClass();return false;" size="10" >search</button>
		
		
		</div>
		<div>
			<p>section id</p><br />
			<select size="10" name="section_id" class="field">
				<option>select a course</option>
			</select>
		</div>

		<input type="submit" value="insert" />
		<button type='button' onclick='window.open(updateFields("StudentEnrollment"),"_self");return false;'>update</button>
		<button type='button' onclick='clearFields();return false;'>clear</button>
	</div>
	<!-- </table> -->
	<!-- <table id="output_table"> -->
	<div id='output_group'>
		<%
		ResourceTool.buildOutputRows(out,"StudentTakingSection");
		ResourceTool.buildOutputRows(out,"StudentQuarterEnrolled");
		%>
	</div>
	<!-- </table> -->
	
	<input type="hidden" name="form" id="form_action" value="StudentEnrollment" />
	<input type="hidden" name="action" id="form_action" value="insert" />
	<input type="hidden" name="class_id" id="form_action" value="" />
</form>

</div>
</div>

</body>
</html>

